//
//  CZStatusListViewModel.swift
//  WeiBoNew
//
//  Created by 秦川 on 16/5/14.
//  Copyright © 2016年 秦川. All rights reserved.
//

import UIKit

class CZStatusListViewModel: NSObject {
    var statusList: [CZStatusViewModel]?
    //获取微博数据
    func requestStatus(complete: (isSuccess: Bool)->()){
        CZNetWorkTools.shareTools.requestStatus(CZUserAccountViewModel.shareUserAccount.accessToken!) { (response, error) -> () in
            if error != nil {
                print("数据有问题")
                print(error)
                complete(isSuccess: false)
                return
            }
            guard let dic = response as? [String: AnyObject] else{
                print("不是一个正确的json文件")
                 complete(isSuccess: false)
                return
            }
            guard let statusArray = dic["statuses"] as? [[String: AnyObject]] else{
                print("不是一个正确的json文件")
                 complete(isSuccess: false)
                return
            }
            //遍历数组
            var tempArray = [CZStatusViewModel]()
            for value in statusArray{
                //  通过status模型转成我们需要viewModel
                let  czstatus = CZStatus(dic: value)
                let statusViewModel = CZStatusViewModel(status: czstatus)
                
                tempArray.append(statusViewModel)
                
            }
            self.statusList = tempArray
//            self.tableView.reloadData()
             complete(isSuccess: true)
        }
    }
}
